package
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Point;

	public class GameDisplay extends Sprite
	{
		private var m_ground:Sprite = new Sprite();
		private var m_background:Sprite = new Sprite();
		
		private var m_cloudsLayer:Sprite = new Sprite();
		private var m_clouds:Vector.<Cloud> = new Vector.<Cloud>;

		private var m_mallOverlay:Sprite;
		
		private var m_syncedDispObjects:Vector.<DisplayObject> = new Vector.<DisplayObject>;
		public function GameDisplay()
		{
			addChild(m_background);
			addChild(m_ground);
			var widthCount:int = 5;
			for(var i:int = 0; i < Game.WIDTH_COUNT; i++){
				for(var j:int = 0; j < 7; j++){
					var skySection:Sprite = Util.getRectSprite(500,250,0x5555ff);
					skySection.x = i*skySection.width;
					skySection.y = j*skySection.height;
					m_background.addChild(skySection);
				}
			}
			
			m_ground.addChild(ImageManager.getFloorSprite());
			
			
			m_background.addChild(m_cloudsLayer);
			m_cloudsLayer.alpha = Math.random()*.35 + .35;
			addClouds();
			
			m_background.x = -m_background.width/2;
			m_background.y = -m_background.height/2;
			m_ground.x = -m_ground.width/2;
			
		}
		
		public function sync(dispObject:DisplayObject):void{
			m_syncedDispObjects.push(dispObject);
		}
		
		public function onMouseDrag(dragVector:Point):void{
			var i:int, il:int;
			for(i = 0, il = m_syncedDispObjects.length; i < il; i++){
				m_syncedDispObjects[i].x += dragVector.x;
				m_syncedDispObjects[i].y += dragVector.y;
			}
			m_ground.x += dragVector.x;
			m_ground.y += dragVector.y;

			m_background.x += dragVector.x/2.5;
			m_background.y += dragVector.y/2.5;			
		}
		
		public function initDisplay():void{
			
		}	

		
		public function step(delta:int):void{
			var i:int, length:int;
			for(i = 0, length = m_clouds.length; i < length; i++){
				m_clouds[i].step(delta);
			}						
		}
		
		
		private function addClouds():void{
			for(var i:int = 0; i < Game.WIDTH_COUNT*4; i++){
				var cloudAsset:DisplayObject = ImageManager.getImage('assets/cloud.png');
				var cloud:Cloud = new Cloud((Math.random() - .5)*2,cloudAsset, m_cloudsLayer, m_background.width, m_background.height);
				m_clouds.push(cloud);
			}
		}
				
	}
}